<?php

class Books_model extends CI_Model {
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function getAll(){
		$stmt = $this->db->conn_id->prepare('SELECT * FROM books');
		$result = $stmt->fetch_all();
        //return $this->db->query('SELECT * FROM books');
    }
    
    function getById($id){
        $query = 'SELECT * FROM books WHERE id = ?';
        $result = $this->db->query($query, array($id));
        return $result->row();        
    }
    
    function insertNewBook($bookInfo){
        $query = 'INSERT INTO books (title, isbn) VALUES (?,?)';
        return $this->db->query($query, array($bookInfo['title'], $bookInfo['isbn']));
    }
    
    function deleteBook($id){
        $query = 'DELETE FROM books WHERE id = ?';
        return $this->db->query($query, array($id));
    }
    
    function updateBook($bookInfo){
        $query = 'UPDATE books SET title = ?, isbn = ? WHERE id = ?';
        return $this->db->query($query, array($bookInfo['title'], $bookInfo['isbn'], $bookInfo['id']));
    }
}
?>